// pages/audit/audit.ts
var { request } = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[] as any,
    passList:[] as any,
    roleList:[] as any
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
   this.initEmployee()
   this.initRoleList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  initRoleList(){
    request('/admin/role/list', {
    }).then((res: any) => {
      if (res.data.code == 1) {
        this.setData({
          roleList: res.data.data
        })
        console.log(this.data.roleList,'roleList');
      }
    })
  },
  initEmployee(){
    request('/admin/employee/page?page=1&pageSize=100', {
    }).then((res: any) => {
      if (res.data.code == 1) {
        let list = res.data.data.records
        this.setData({
          list: list.filter((item:any)=>item.processStatus==0&&
          item.status==1),
          passList: list.filter((item:any)=>item.processStatus==1&&
          item.status==1)
        })
        console.log(this.data.list,this.data.passList,'list');
      }
    })
  },
  handleAudit(e){
    let param = e.currentTarget.dataset
    console.log(param,'param');
    let that = this
    wx.showModal({
      content: `确认${param.status==1?'通过':'拒绝'}当前账号申请？`,
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          request(`/admin/employee/processStatus?id=${param.id}&processStatus=${param.status}`, {
            method:'POST',
          }).then((res: any) => {
            if (res.data.code == 1) {
              that.initEmployee()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  handleDelete(e){
    let param = e.currentTarget.dataset
    console.log(e.currentTarget.dataset);
    let that = this
    wx.showModal({
      content: '确认删除当前账号？',
      success (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          request(`/admin/employee/status?id=${param.id}&status=${0}`, {
            method:'POST',
          }).then((res: any) => {
            if (res.data.code == 1) {
              that.initEmployee()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})